﻿using Appliaction.Dto.Base_Manage;
using Appliaction.IAppServices.Base_Manage;
using AutoMapper;
using Domain.Entitys.Base_Manage;
using Domain.IRepositorys.Base_Manage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Base_Manage
{
    public class RolesService : IRolesService
    {
        private readonly IRolesRepository rolesRepository;
        private readonly IMapper mapper;

        public RolesService(IRolesRepository rolesRepository,IMapper mapper)
        {
            this.rolesRepository = rolesRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 根据用户ID查询对应的角色
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<Sys_Role> GetRolesAsync(int userId)
        {
            return await rolesRepository.GetRolesAsync(userId);
        }

        /// <summary>
        /// 查询所有可用角色
        /// </summary>
        /// <returns></returns>
        public Task<List<Sys_Role>> GetRolesFillAsync()
        {
            return rolesRepository.GetRolesFillAsync();
        }

        /// <summary>
        /// 添加用户角色信息
        /// </summary>
        /// <param name="userRolesAddDto"></param>
        /// <returns></returns>
        public async Task<int> UserRolesAddAsync(UserRolesAddDto userRolesAddDto)
        {
            Sys_User_Role sys_UserRoles = mapper.Map<Sys_User_Role>(userRolesAddDto);
            return await rolesRepository.UserRolesAddAsync(sys_UserRoles);
        }

        /// <summary>
        /// 根据用户ID删除用户角色ID
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public async Task<int> UserRolesRemoveAsync(int userId)
        {
            return await rolesRepository.UserRolesRemoveAsync(userId);
        }
    }
}
